'''
Created on 2011/03/10

@author: Administrator
'''

import datetime
from util.models import PlayTime
from google.appengine.ext import db

class PlayTimeClass():
    '''
    classdocs
    '''
    def __init__(self):
        self.timePlay=0
    
    def getTimePlay(self):
        return self.timePlay
    
    def getPlayTime(self,playerID):
        playTimes = PlayTime.gql('WHERE playerID = :1 LIMIT 1', playerID)
        playTime=playTimes.get()
        if playTime==None:
            playTime = PlayTime(playerID=playerID,playDate=datetime.date.today(),playTime=0)
            playTime.put()
        self.timePlay = playTime.playTime
        return playTime
    
    def updatePlayTime(self,playerID):
        playTime=self.getPlayTime(playerID)
        playTime.playDate=datetime.date.today()
        playTime.playTime+=1
        self.timePlay = playTime.playTime
        db.put(playTime)     